package com.server;

import java.util.Date;

import org.apache.log4j.Logger;
import org.xsocket.connection.Server;

import com.connect.server.handler.ChatHandler;
import com.connect.server.handler.DbHandler;
import com.connect.server.handler.WorldDataHandler;
import com.game.base.BaseSimulation;
import com.module.assignment.AssignmentManager;
import com.module.itemeditor.EditorManager;

public class ServerSimulation extends BaseSimulation {
	
	private Server server;
	private WorldDataHandler handler;
	
	//用于查询数据的服务器
	private Server dbServer;
	private DbHandler dbHandler;
	
	private Server chatServer;
	private ChatHandler chatHandler;
	
	public static boolean isDev = true;
	
	public void startUp() {
		try {
			handler = new WorldDataHandler();
			server = new Server(8888, handler);
			server.start();
			Logger.getRootLogger().info(new Date() + "游戏主服务开启！");
		} catch (Exception e) {
			Logger.getRootLogger().error(
					new Date() + "游戏主服务开启失败！" + e.getMessage());
		}
		try {
			dbHandler = new DbHandler();
			dbServer = new Server(6666,dbHandler);
			dbServer.start();
			Logger.getRootLogger().info(new Date() + "数据查询服务开启！");
			
		} catch (Exception e) {
			Logger.getRootLogger().error(
					new Date() + "数据查询服务开启失败！" + e.getMessage());
		}
		try {
			chatHandler = new ChatHandler(); 
			chatServer = new Server(3500,chatHandler);
			chatServer.start();
			Logger.getRootLogger().info(new Date() + "聊天服务开启成功！");
		} catch (Exception e) {
			Logger.getRootLogger().error(new Date() + "聊天服务开启失败！" + e.getMessage());
		}
		
		try{
			AssignmentManager.setup();
			Logger.getRootLogger().info(new Date() + "委派管理器开启成功！");
		} catch (Exception e) {
			Logger.getRootLogger().error(new Date() + "委派管理器开启失败！");
		}
		
		try{
			EditorManager.setup();
			Logger.getRootLogger().info(new Date() + "物品编辑器开启成功！");
		} catch (Exception e) {
			Logger.getRootLogger().error(new Date() + "物品编辑器开始失败！");
		}
	}
}
